<template>
	<view class="page">
		<uni-forms ref="baseForm" :modelValue="baseFormData">
			<uni-forms-item label="收货人" required><uni-easyinput v-model="baseFormData.name" placeholder="请输入收货人姓名" /></uni-forms-item>
			<uni-forms-item label="手机号码" required><uni-easyinput v-model="baseFormData.phone" placeholder="请输入收货人手机号码" /></uni-forms-item>
			<picker class="address" mode="region" @change="bindAddressChange">收货地址</picker>
			<view class="addressText">{{ address }}</view>
			<!-- <view class="line4">————————————————————————————————————————————————————</view> -->
			<uni-forms-item label="详细地址" required><uni-easyinput v-model="baseFormData.place" placeholder="请输入详细地址" /></uni-forms-item>
		</uni-forms>
		<button class="btn" @click="insert">确认添加</button>
	</view>
</template>

<script>
export default {
	data() {
		return {
			address: '',
			baseFormData: {
				name: '',
				phone: '',
				place:''
			}
		};
	},
	methods: {
		bindAddressChange: function(e) {
			this.region = e.target.value;
			this.address = this.region[0] + this.region[1] + this.region[2];
			console.log(this.address);
		},
		insert() {
			let that = this;
			let data = {
				address: that.address + that.baseFormData.place,
				name: that.baseFormData.name,
				phone: that.baseFormData.phone
			};
			that.ajax(that.url.insertAddressInfo, 'POST', data, function(resp) {
				uni.showToast({
					icon: 'none',
					title: '添加成功'
				});
				setTimeout(function() {
					uni.navigateBack(1);
				}, 1000);
				that.address = '',
				that.baseFormData.place = ''
				that.baseFormData.name = '',
				that.baseFormData.phone = ''
			});
		}
	}
};
</script>

<style lang="less">
@import url('insert_addressInfo.less');
</style>
